//
//  BabyPhoto.m
//  BabyHelper
//
//  Created by  thomas on 11-7-30.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "BabyPhotoEntry.h"
#import "BabyProfile.h"
#import "Dao.h"

@implementation BabyPhotoEntry
@synthesize index,name,thumPath,photoPath,comments,timestamp,babyGrowID,categoryID;
@synthesize latitude,longitude,location;


//thomas_ consider to optimize the memory leak of array
-(NSString*) getSummaryString {
	Dao *dao = [Dao getInstance];
	BabyProfile *babyProfile = [[[BabyProfile alloc]init] autorelease];
	[dao LoadBabyProfile:babyProfile];
	if (self.babyGrowID > 0 ) {
		BabyGrowEntry *entry = [dao QueryBabyGrowEntryWithGrowID:self.babyGrowID];
		if (entry != nil) {
			return [entry getSummaryString];
		}
		else
			return self.comments;
	}
	else
	{
		NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
		[dateFormatter setDateFormat:DATE_FORMAT];
		NSString *description = [dateFormatter stringFromDate:self.timestamp];
		[dateFormatter release];
		if(self.location != nil )
		{
			if (![self.location isEqualToString:@"null"] )
			{
				description = [description stringByAppendingString:@","];
				description = [description stringByAppendingString:self.location];
			}
		}
		return description;
	}
}

-(NSString*) getSummaryStringWithoutTimestamp {
	Dao *dao = [Dao getInstance];
	BabyProfile *babyProfile = [[[BabyProfile alloc]init] autorelease];
	[dao LoadBabyProfile:babyProfile];
	if (self.babyGrowID > 0 ) {
		BabyGrowEntry *entry = [dao QueryBabyGrowEntryWithGrowID:self.babyGrowID];
		if (entry != nil) {
			return [entry getSummaryString];
		}
		else
			return self.comments;
	}
	else
	{
		NSString *description = @"";
		if(self.location != nil )
		{
			if (![self.location isEqualToString:@"null"] )
			{
				description = [description stringByAppendingString:self.location];
			}
		}
		if(self.comments != nil )
		{
			if (![self.comments isEqualToString:@"null"] )
			{
				description = [description stringByAppendingString:self.comments];
			}
		}		
		return description;
	}
}
@end

@implementation PhotoAlbumEntry
@synthesize index,name,comments,timestamp;
@end